<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>comic</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<link type="text/css" rel="stylesheet" href="../../css/pepper-grinder/jquery-ui-1.8.16.custom.css" />
	<link type="text/css" rel="stylesheet" href="css/news.css" />
	<script type="text/javascript" src="../../js/jquery.min.js"></script>
	<script type="text/javascript" src="../../js/jquery-ui-1.8.16.custom.min.js"></script>
	<script type="text/javascript" src="../../js/jquery.mousewheel.min.js"></script>
	<script src="http://api.map.baidu.com/api?v=1.2" type="text/javascript"></script>
	<script language="JavaScript" type="text/JavaScript">
		var map;
		var cityname;
		$(document).ready(function() {
			$(window).resize(function() {
				refresh();
			});
			refresh();
			
			map = new BMap.Map("container");          // 创建地图实例
			var point = new BMap.Point(116.404, 39.915);  // 创建点坐标
			map.centerAndZoom(point, 15);                 // 初始化地图，设置中心点坐标和地图级别
			map.enableScrollWheelZoom();                  // 启用滚轮放大缩小。
			map.enableKeyboard();                         // 启用键盘操作。
			var opts = {type: BMAP_NAVIGATION_CONTROL_SMALL}  
			map.addControl(new BMap.NavigationControl(opts)); 
			
			var myCity = new BMap.LocalCity();
			myCity.get(myFun);
			
		
		});
		function myFun(result){
				cityname = result.name;
				map.setCurrentCity(cityname);  
				//map.setCenter(cityname);
				goMap("兴顺街52号");
				
		}

		function goMap(address){
			// 创建地址解析器实例
			var myGeo = new BMap.Geocoder();
			
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(address, function(point){
				
				if (point) {
					map.centerAndZoom(point, 16);
					var marker = new BMap.Marker(point);
					map.addOverlay(marker);
					//添加热区
					//var hotSpot = new BMap.Hotspot(point, {text: address, minZoom: 8, maxZoom: 18});
					//map.addHotspot(hotSpot);
					
					var sContent = "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>"+address+"</h4>";
						
					
					var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
					
					marker.addEventListener("click", function(){  
						
						this.openInfoWindow(infoWindow);  
					});
					//var local = new BMap.LocalSearch(map, {  
					//	renderOptions:{map: map, autoViewport: true}  
					//});  
					//local.searchInBounds("学校", map.getBounds());  
					//local.searchNearby("学校", address);
				}else{
					
					goDefaultMap();

				}
			}, cityname);
			

			
		}

		function goDefaultMap(){
			// 创建地址解析器实例
			var myGeo = new BMap.Geocoder();
			
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(cityname, function(point){
				
				if (point) {
					map.centerAndZoom(point, 16);
					var marker = new BMap.Marker(point);
					map.addOverlay(marker);
					//添加热区
					//var hotSpot = new BMap.Hotspot(point, {text: address, minZoom: 8, maxZoom: 18});
					//map.addHotspot(hotSpot);
					var sContent =
						"<h4 style='margin:0 0 5px 0;padding:0.2em 0'>"+cityname+"</h4>" + 
						"<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>请输入详细地址</p>" +
						"<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'><input type='text' id='newadress'><input type='button' value='更新' onclick='modifyMap();'/></p>";
					
					var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
					
					marker.addEventListener("click", function(){  
						
						this.openInfoWindow(infoWindow);  
					});
				}else{
					
					map.setCenter(cityname);

				}
			}, cityname);
		}
		function modifyMap(){
			var newadress = $("#newadress").val();
			goMap(newadress);

		}

		function refresh(){
			var winheight = $(window).height();
			var winwidth = $(window).width();
			$("#bodydiv").css("height",winheight);
			$("#container").css("height",winheight);
		}

		function showNews(obj){
			
			window.parent.showapp("compents/news/shownews.html?id="+obj.id);
		}

		
	</script>
</head>
<body style="background-color=transparent;width:100%;margin-left:0px;margin-top:0px;">
	<div id="bodydiv" style="background:url(../../css/pepper-grinder/images/ui-bg_fine-grain_10_eceadf_60x60.png)">
		
		<div id="container" style="width:100%;"></div>
	
	</div>
	
	
	
</body>
</html>